package com.cjm.algorithm.leetcode;

import java.util.*;
import java.util.stream.Collectors;

/**
 * {link https://leetcode-cn.com/problems/contains-duplicate/}
 */
public class ContainsDuplicate217 {
    public static boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>(nums.length);
        for (int num : nums) {
            set.add(num);
        }
        return set.size() != nums.length;
    }

    public static boolean containsDuplicate1(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            Integer integer = map.get(num);
            if (integer != null) {
                return true;
            }
        }
        return false;
    }

    public static boolean containsDuplicate2(int[] nums) {
        Set<Integer> collect = Arrays.stream(nums).boxed().collect(Collectors.toSet());
        return collect.size() != nums.length;
    }
}
